import json
import app
from lib.dbutil import DBUtil



#读取db
def read_db_data():
    test_data = []
    db_data = DBUtil.exe_sql("select * from ihrm_login;")

    for case_data in db_data:
        if case_data[2] is not None:
            login_data = eval(case_data[2])
        else:
            login_data = case_data[2]
        status_code = case_data[3]
        success = case_data[4]
        code = case_data[5]
        message = case_data[6]
        test_data.append((login_data, status_code, success, code, message))

    return test_data

if __name__ == '__main__':
    print(read_db_data())
#读取json
def read_json_file():
    json_file = app.BASE_DIR + "/data/login.json"
    test_data = []
    with open(json_file,encoding="utf-8") as f:
        json_data = json.load(f)
        for case_data in json_data:
            login_data = case_data.get("login_data")
            status_code = case_data.get("status_code")
            success = case_data.get("success")
            code = case_data.get("code")
            message = case_data.get("message")
            test_data.append((login_data,status_code,success,code,message))

    return test_data







# 封装公共断言方法
def common_assert(case, response, status_code=200, success=True, code=10000, message="操作成功"):
    case.assertEqual(status_code, response.status_code)
    case.assertEqual(success, response.json().get("success"))
    case.assertEqual(code, response.json().get("code"))
    case.assertIn(message, response.json().get("message"))


